Revert "Use llvm symbolizer for stack script." This reverts commit b6e038a7a7b07f680eba6d6ec1c32319ae89cd78. Reason for revert: Broke stack_tool_with_logcat_dump on WebKit Android (Nexus4): https://uberchromegw.corp.google.com/i/chromium.webkit/builders/WebKit%20Android%20%28Nexus4%29/builds/72002 Original change's description: > Use llvm symbolizer for stack script. > > llvm symbolizer is a more efficient symbolizer than addr2line, objdump, > etc. > > In this cl, I 1)created a wrapper instance to interact with > llvm symbolizer, 2)made the stack script to use llvm symbolizer instance, > and then 3)added llvm symbolizer into isolated inputs. > > Bug: 774267 > Change-Id: I971fb808b97f3a569eb9615f99efa41e3a56f3cb > Reviewed-on: https://chromium-review.googlesource.com/789376 > Reviewed-by: agrieve <agrieve@chromium.org> > Reviewed-by: Dirk Pranke <dpranke@chromium.org> > Commit-Queue: Zhiling Huang <hzl@chromium.org> > Cr-Commit-Position: refs/heads/master@{#521820} TBR=dpranke@chromium.org,agrieve@chromium.org,hzl@chromium.org,bpastene@chromium.org,jbudorick@chromium.org Change-Id: Ieebbcb9527dafd25a0fc74d2826a31162495c86e No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: 774267 Reviewed-on: https://chromium-review.googlesource.com/809941 Reviewed-by: Derek Cheng <imcheng@chromium.org> Commit-Queue: Derek Cheng <imcheng@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#521898} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 5b391ee57fc58d4beae41346195ed4e1d0fca853diff --git a/llvm_symbolizer.py b/llvm_symbolizer.py deleted file mode 100644 index fd0df11..0000000 --- a/llvm_symbolizer.py +++ /dev/null
@@ -1,110 +0,0 @@ -# Copyright 2017 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -import logging -import os -import re -import subprocess -import threading - -_CHROME_SRC = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir) -_LLVM_SYMBOLIZER_PATH = os.path.join( - _CHROME_SRC, 'third_party', 'llvm-build', 'Release+Asserts', 'bin', - 'llvm-symbolizer') - -_BINARY = re.compile(r'0b[0,1]+') -_HEX = re.compile(r'0x[0-9,a-e]+') -_OCTAL = re.compile(r'0[0-7]+') - -_UNKNOWN = '<UNKNOWN>' - - -def _CheckValidAddr(addr): - """ - Check whether the addr is valid input to llvm symbolizer. - Valid addr has to be octal, binary, or hex number. - - Args: - addr: addr to be entered to llvm symbolizer. - - Returns: - whether the addr is valid input to llvm symbolizer. - """ - return _HEX.match(addr) or _OCTAL.match(addr) or _BINARY.match(addr) - - -class LLVMSymbolizer(object): - def __init__(self): - """Create a LLVMSymbolizer instance that interacts with the llvm symbolizer. - - The purpose of the LLVMSymbolizer is to get function names and line - numbers of an address from the symbols library. - """ - self._llvm_symbolizer_subprocess = None - # Allow only one thread to call GetSymbolInformation at a time. - self._lock = threading.Lock() - - def Start(self): - """Start the llvm symbolizer subprocess. - - Create a subprocess of the llvm symbolizer executable, which will be used - to retrieve function names etc. - """ - if os.path.isfile(_LLVM_SYMBOLIZER_PATH): - self._llvm_symbolizer_subprocess = subprocess.Popen( - [_LLVM_SYMBOLIZER_PATH], stdout=subprocess.PIPE, stdin=subprocess.PIPE) - else: - logging.error('Cannot find llvm_symbolizer here: %s.' % - _LLVM_SYMBOLIZER_PATH) - self._llvm_symbolizer_subprocess = None - - def Close(self): - """Close the llvm symbolizer subprocess. - - Close the subprocess by closing stdin, stdout and killing the subprocess. - """ - with self._lock: - if self._llvm_symbolizer_subprocess: - self._llvm_symbolizer_subprocess.kill() - self._llvm_symbolizer_subprocess = None - - def __enter__(self): - """Start the llvm symbolizer subprocess.""" - self.Start() - return self - - def __exit__(self, exc_type, exc_val, exc_tb): - """Close the llvm symbolizer subprocess.""" - self.Close() - - def GetSymbolInformation(self, lib, addr): - """Return the corresponding function names and line numbers. - - Args: - lib: library to search for info. - addr: address to look for info. - - Returns: - A list of (function name, line numbers) tuple. - """ - if (self._llvm_symbolizer_subprocess is None or not lib - or not _CheckValidAddr(addr) or not os.path.isfile(lib)): - return [(_UNKNOWN, lib)] - - with self._lock: - self._llvm_symbolizer_subprocess.stdin.write('%s %s\n' % (lib, addr)) - self._llvm_symbolizer_subprocess.stdin.flush() - - result = [] - # Read till see new line, which is a symbol of end of output. - # One line of function name is always followed by one line of line number. - while True: - line = self._llvm_symbolizer_subprocess.stdout.readline() - if line != '\n': - line_numbers = self._llvm_symbolizer_subprocess.stdout.readline() - result.append( - (line[:-1], - line_numbers[:-1])) - else: - return result